import BaseWindow from "../common-components/BaseWindow";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu('game/ResultWnd')
export default class ResultWnd extends BaseWindow {

    @property(cc.Label)
    countLbl: cc.Label = null;

    @property(cc.Node)
    heartNode: cc.Node = null;

    private _heartNodePos: cc.Vec2 = null;

    hearts: number = 0;

    protected onLoad(): void {
        this._heartNodePos = cc.v2(this.heartNode.getPosition());
    }

    initUI(hearts: number) {
        this.hearts = hearts;

        this.countLbl.string = hearts + '';
    }

    protected onCollectBtnClicked() {
        cc.log(`onCollectBtnClicked`);
        // this.closeWind();
    }

    doCollect(targetPosInWorld: cc.Vec2, cb?: () => void) {

        const pos = this.heartNode.parent.convertToNodeSpaceAR(targetPosInWorld);
        this.heartNode.setPosition(this._heartNodePos);
        this.heartNode.active = true;

        cc.tween(this.heartNode)
            .to(.4, { position: cc.v3(pos) }, { easing: 'sineIn' })
            .set({ active: false })
            .call(() => {
                cb && cb();
            })
            .start();
    }
}
